package com.example.supernote.model.note.commands.Insert

import androidx.compose.ui.text.input.TextFieldValue
import com.example.supernote.R
import com.example.supernote.model.note.commands.AbstractCommand
import com.example.supernote.model.note.commands.insertTextAtRange
import com.example.supernote.model.note.context.Context

class InsertCodeCommand: AbstractCommand(R.string.note_insert_code) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("\n```python\n\n", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class InsertLineCodeCommand: AbstractCommand(R.string.note_insert_code_line) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("`", "`")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class InsertMathCommand: AbstractCommand(R.string.note_insert_math) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("$", "$")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class InsertQuoteCommand: AbstractCommand(R.string.note_insert_quote) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("> ", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class InsertLineCommand: AbstractCommand(R.string.note_insert_line) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("---", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class InsertLinkCommand: AbstractCommand(R.string.note_insert_link) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf(context.generateText, "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class GenerateCodeCommand: AbstractCommand(R.string.note_gen_code) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("\n" + context.generateText + "\n", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class UploadImageCommand: AbstractCommand(R.string.note_upload_image) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("<img src='${context.uri}' alt='${context.name}' style='max-width: 100%; height: auto;'>\n", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class GenerateImageCommand: AbstractCommand(R.string.note_gen_image) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("<img src='${context.generateText}' style='max-width: 100%; height: auto;'>\n\n", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class OcrImageCommand: AbstractCommand(R.string.note_ocr) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("\n" + context.generateText + "\n\n", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class UploadAudioCommand: AbstractCommand(R.string.note_upload_audio) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("<audio src='${context.uri}' controls></audio>", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class OcrAudioCommand: AbstractCommand(R.string.note_convert_audio) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("\n" + context.generateText + "\n\n", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}

class UploadVideoCommand: AbstractCommand(R.string.note_upload_video) {
    override fun execute(context: Context): TextFieldValue =
        insertTextAtRange(
            currentTextFieldValue = context.article,
            textRange = context.selection,
            insertText = listOf("<video src='${context.uri}' style='max-width: 100%; height: auto' controls></video>", "")
        )

    override fun undo(context: Context) {
        println(stringResId)
    }
}